package graphicinterface;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 * Almost every window from our system will be displayed on a full screen JFrame that has
 * a menu that lets the user go back to the first window showed(the main menu).
 * Because of that, we'll maintain this behavior on this class.
 * It's a special type of JFrame that has window size and menu with option to go back to
 * main menu.
 * @author Mina
 *
 */
public class JFrameWithMenu extends JFrame implements MouseListener
{
	private JMenuItem goBackToMainMenu;
	private JMenuItem exit;
	public JFrameWithMenu(String windowName)
	{
		this.setTitle(windowName);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		this.setSize(d);
		
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setAlwaysOnTop(true);
		
		JMenuBar menuBar = new JMenuBar();
		JMenu menu = new JMenu("menu");
		menuBar.add(menu);
		this.goBackToMainMenu = new JMenuItem("go back to main menu");
		this.exit = new JMenuItem("exit");
		this.goBackToMainMenu.addMouseListener(this);
		this.exit.addMouseListener(this);
		menu.add(goBackToMainMenu);
		menu.add(exit);
		this.setJMenuBar(menuBar);
	}
	
	@Override
	public void mouseClicked(MouseEvent arg0) 
	{
		
	}
	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mousePressed(MouseEvent arg0) 
	{
		Object objectClicked = arg0.getSource();
		
		if(objectClicked == this.goBackToMainMenu)
		{
			/*user clicked on the option of the menu that let's him go back to the first screen
			 that was presented to him(the main menu)*/
			WindowInitialScreen inicialScreen = new WindowInitialScreen();
			this.dispose();
		}
		else if(objectClicked == this.exit)
		{
			//user wants to shut down application
			System.exit(0);
		}
		
	}
	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
